package com.mp.controller.rest;

import com.mp.controller.rest.util.MemoryPriceRest;
import com.mp.controller.rest.util.MensagemRetornoRest;
import com.mp.negocio.SessaoUsuarioService;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

@Path("/Autenticacao")
public class AutenticacaoRest extends MemoryPriceRest
{
    private SessaoUsuarioService sessaoService = new SessaoUsuarioService();
    
    @GET
    @Produces("application/json")
    @Path("/Autenticar")
    public MensagemRetornoRest getSessaoUsuario(
            @QueryParam("login")String login,
            @QueryParam("senha")String senha) 
    {
        try
        {           
            return this.setRetornoCorreto(sessaoService.autenticarUsuario(login, senha));
        }
        catch(Exception ex)
        {
            return this.setRetornoComErro(ex);
        }
    }
    
    @PUT
    @Produces("application/json")
    @Path("/LogOut")
    public MensagemRetornoRest setLogOut(
            @FormParam("idSessao")String idSessao
           ) 
    {
        try
        {   
            sessaoService.logOut(Integer.parseInt(idSessao));    
            return this.setRetornoCorreto("ok");
        }
        catch(Exception ex)
        {
            return this.setRetornoComErro(ex);
        }
    }
}
